package message.util;

import java.util.HashMap;
import java.util.Map;

public class BiHashMap<K, V, T> {
	
	public static class Pair<V, T> {
		private V val1;
		private T val2;
		public V getFormer() {
			return val1;
		}
		public T getLater() {
			return val2;
		}
		private Pair(V val1, T val2) {
			this.val1 = val1;
			this.val2 = val2;
		}
	}
	
	private Map<K, Pair<V, T>> map;
	
	public BiHashMap() {
		this.map = new HashMap<>();
	}
	
	public static <V, T> Pair<V, T> wrapPair(V val1, T val2){
		return new Pair<V, T>(val1, val2);
	}
	
	public void put(K key, V val1, T val2) {
		this.map.put(key, new Pair<V, T>(val1, val2));
	}
	
	public void put(K key, Pair<V, T> v) {
		this.map.put(key, v);
	}
	
	public V getFormer(K key) {
		var x = this.map.get(key);
		if(x == null) return null;
		return x.val1;
	}
	
	public T getLater(K key) {
		var x = this.map.get(key);
		if(x == null) return null;
		return x.val2;
	}
	
	public Pair<V, T> get(K key){
		return this.map.get(key);
	}
	
}
